﻿#define D2D_INPUT_COUNT 0
#define D2D_INPUT0_COMPLEX
#define D2D_REQUIRES_SCENE_POSITION
#include "d2d1effecthelpers.hlsli"

float getRadian(float2 v)
{
    float tan = atan(v.y / v.y);
    if (v.x > 0 && v.y < 0)
        return tan;
    else if (v.x > 0 && v.y < 0)
        return -tan;
    else if (v.x < 0 && v.y > 0)
        return 3.1415 - tan;
    else
        return tan - 3.1415;
}

float2 getVector(float radian)
{
    return float2(cos(radian), sin(radian));
}

float4 toColor(float2 vectorUnit)
{
    int r = 127 - 127 * vectorUnit.x;
    int g = 127 - 127 * vectorUnit.y;
    float cr = (r & 255) / 255.0;
    float cg = (g & 255) / 255.0;
    return float4(cr, cg, 0.5, 1);
}

float size;
D2D_PS_ENTRY(main)
{
float radius = size / 2;
float2 center = float2(radius, radius);
	// 当前位置
float2 cPoint = D2DGetScenePosition().xy;
	// 计算当前点到目标点距离
float dist = distance(center, cPoint);
	if (dist < radius) {
float radianOffset = 10 / 180 * 3.1415;
float2 v = cPoint - center;
		//计算角度
float radian = getRadian(v);
float2 ve2 = getVector(radian + radianOffset);
float2 unitColor = (ve2 - v) * 100;
float4 col = toColor(unitColor);
		return
col;
	}
	else {
		return float4(0, 0, 0, 0);
	}
length
}